<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
	<%@include file="/WEB-INF/jspf/adminPage.jspf" %>
	<%@include file="/WEB-INF/jspf/meta/meta.jspf" %>
	<%@include file="/WEB-INF/jspf/css_js/easyui_grid_tools_js.jspf"%>
<title>教师信息列表</title>
</head>
<body>
<div style="padding-top: 10px"></div>
		<table class="easyui-datagrid" id="dg_Teacher"
			data-options="fit:true,fitColumns:true,singleSelect:false,pagination:true,collapsible:true,toolbar:'#tb',url:'<%=request.getContextPath()%>/teacher/TeacherList.json?',method:'get'">
			<thead>
				<tr>
					<th field="ck" checkbox="true"></th>
					<th data-options="field:'teacherId',width:80,aling:'center'">教师编号</th>
					<th data-options="field:'teacherName',width:100,aling:'center'">教师姓名</th>
					<th data-options="field:'teacherBirthday',width:100,aling:'center'">教师生日</th>
					<th data-options="field:'teacherPhone',width:100,aling:'center'">教师电话</th>
					<th data-options="field:'teacherAddr',width:100,aling:'center'">教师地址</th>
					<th data-options="field:'teacherSex',width:100,aling:'center'">教师性别</th>
					<th data-options="field:'teacherEmail',width:100,aling:'center'">教师邮箱</th>
					<th data-options="field:'teacherAccount',width:100,aling:'center'">教师账号</th>
					<th data-options="field:'teacherPassword',width:100,aling:'center'">教师密码</th>
					<th
						data-options="field:'teacherStartdate',width:100,aling:'center'">教师入职日期</th>
					<th data-options="field:'teacherEnddate',width:100,aling:'center'">教师离职日期</th>
					<th data-options="field:'teacherSytle',width:250,aling:'center'">状态</th>

				</tr>
			</thead>
		</table>
	<div id="tb">
		<div>
			<c:if test="${code.contains('teacher:add')}">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick="addTea()">添加</a>
			</c:if>

			<c:if test="${code.contains('teacher:update')}">
				<a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick="updateTea()">修改</a>
			</c:if>

			<c:if test="${code.contains('teacher:dell')}">
				<a href="#" class="easyui-linkbutton" iconCls="icon-remove" onclick="deleteTeacher()">删除</a>
			</c:if>

			教师状态：<select  class="easyui-combobox" id="t_style" name="style"  data-options="editable:false"
						  style="width: 100px;">

			<option value="离职" >离职</option>
			<option value="在职"  >在职</option>
			<option value="" selected="selected" >所有</option>
		</select>
			教师名称：<input type="text" id="findName" value="" name="findName" style="width: 100px" />
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="forLike()">查询</a> &nbsp;&nbsp;
			<c:if test="${code.contains('teacher:down')}">
				<a href="javascript:void(0)" onclick="dowan()">导出Excel数据</a>
			</c:if>
			&nbsp;&nbsp;
			<c:if test="${code.contains('teacher:upload')}">
				<form id="upfile" style="display: inline;">
					<input id="file" name="file" type="file" style="width: 170px"/>
					<input type="button" value="导入Excel数据"  onclick="upload()"/>
				</form>
			</c:if>
		</div>
	</div>
	<!-- 引入添加页面 -->
	<%@ include file="/WEB-INF/jsp/teacher/addTeacher.jspf" %>
	<!-- 引入修改页面 -->
	<%@ include file="/WEB-INF/jsp/teacher/updateTeacher.jspf" %>
		<script type="text/javascript">

		//异步提交表单
		function check(){
			if($('#file').val()==null||$('#file').val()==''){
				alert("请选择需要上传的Excel文件！")
				return false;
			}
			return true;
		}
		function upload(){
			if(check()==true){
				var formData=new FormData();
				formData.append('file',$('#file')[0].files[0]);
					$.ajax({
						url: "<%=request.getContextPath()%>/teacher/upload.json",
						type: "POST",
						data: formData,
						 processData:false,
			             contentType:false,
						success: function (data) {
							$.messager.show({
								title:'操作提示',
								msg:data.msg,
								timeout:3000,
								showType:'slide'
							});
			                $("#dg_Teacher").datagrid('reload')
			                $('#file').clear();
			   
						},
						error: function () {
							alert("上传失败！");
		 
						}
					});	
				}
		}
			
		//根据姓名重新向后台请求数据，表跟根据返回的data生成数据
		function forLike(){
			var name=$('#findName').val()
			var style=$('#t_style option:selected').val()
			   $.ajax({
		            url : "<%=request.getContextPath()%>/teacher/TeacherList.json?style="+style+"&findName="+name
		            ,success : function(data) {
		                $("#dg_Teacher").datagrid("loadData", data.rows); //动态取数据
		            }
		        });
		}
		//添加方法
		function addTea() {
			$('#win_Teacheradd').window('open')
		}
		//修改方法
		function updateTea() {
			var rows=$('#dg_Teacher').datagrid('getChecked')
			if(rows.length==0){
				$.messager.show({
					title:'操作提示',
					msg:'请选择需要操作的数据',
					timeout:3000,
					showType:'slide'
				});
				return;
			}else if(rows.length>1){
				$.messager.show({
					title:'操作提示',
					msg:'请选择一条需要操作的数据进行操作',
					timeout:3000,
					showType:'slide'
				});
				return;
			}
			$('#ff_teacherUpdate').form('load','<%=request.getContextPath()%>/teacher/dataForm.json?tid='+rows[0].teacherId)
			$('#win_Teacherupdate').window('open')
		}
		
		//批量删除方法
		function deleteTeacher(){
			var rows=$('#dg_Teacher').datagrid('getChecked')
			if(rows.length==0){
				$.messager.show({
					title:'操作提示',
					msg:'请选择需要操作的数据进行操作',
					timeout:3000,
					showType:'slide'
				});
				return;
			}
			var tId=[];
			for (var i = 0; i < rows.length; i++) {
				tId.push(rows[i].teacherId)
			}
			 $.ajax({url:"<%=request.getContextPath()%>/teacher/deleteTeacher.json?list="+tId
				 ,success:function(data){
						$.messager.show({
							title:'操作提示',
							msg:data.msg,
							timeout:5000,
							showType:'slide'
						});
					 $('#dg_Teacher').datagrid('reload');
		    }});
		}
		function dowan(){
			var url='<%=request.getContextPath()%>/teacher/download'
			window.location=url
		}
		</script>
</body>
</html>